package com.jwdf.uda.ui.fragment.question.bean;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import com.jwdf.uda.bean.PbBean;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * Created by fatsfan on 2016/9/18.
 */
public class NewAnswer implements Parcelable {

    public static final Parcelable.Creator<NewAnswer> CREATOR = new Parcelable.Creator<NewAnswer>() {
        @Override
        public NewAnswer createFromParcel(Parcel source) {return new NewAnswer(source);}
        @Override
        public NewAnswer[] newArray(int size) {return new NewAnswer[size];}
    };
    private static NewAnswer instance;
    private int id;
    private String title;
    private String mDescribe = "";
    private List<String> imageList = new ArrayList<>();
    private Map<String, String> mURLToken = new HashMap<>();
    private List<EditDescribe> editDescribeList = new ArrayList<>();
    private PbBean.PbSignBaseVoteOptionType vote = PbBean.PbSignBaseVoteOptionType.VOTE_OPTION_TYPE_NONE;
    private Context mContext;
    private boolean mIsUpload = true;
    private List<File> imageFileList = new ArrayList<>();

    public NewAnswer() {}

    protected NewAnswer(Parcel in) {
        this.id = in.readInt();
        this.mDescribe = in.readString();
        this.imageList = in.createStringArrayList();
        int mURLTokenSize = in.readInt();
        this.mURLToken = new HashMap<String, String>(mURLTokenSize);
        for(int i = 0; i < mURLTokenSize; i++) {
            String key = in.readString();
            String value = in.readString();
            this.mURLToken.put(key, value);
        }
        this.editDescribeList = new ArrayList<EditDescribe>();
        in.readList(this.editDescribeList, EditDescribe.class.getClassLoader());
        int tmpVote = in.readInt();
        this.vote = tmpVote == -1 ? null : PbBean.PbSignBaseVoteOptionType.values()[tmpVote];
    }
    public static synchronized NewAnswer getInstance() {
        if(instance == null) {
            Log.i("----NewAnswer 数据空", "NewAnswer----------------------");
            instance = new NewAnswer();
        }
        return instance;
    }
    public void delete() {
        mDescribe = "";
        imageList.clear();
        editDescribeList.clear();
        vote = PbBean.PbSignBaseVoteOptionType.VOTE_OPTION_TYPE_NONE;
        mIsUpload = true;
        mContext = null;
        imageFileList.clear();
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }

    public String getmDescribe() {
        return mDescribe;
    }
    public void setmDescribe(String mDescribe) {
        this.mDescribe = mDescribe;
    }

    public List<File> getImageFileList() {
        return imageFileList;
    }

    public void setImageFileList(List<File> imageFileList) {
        this.imageFileList = imageFileList;
    }

    public void addImageFileList(File file, int i) {
        this.imageFileList.add(i, file);
    }

    public PbBean.PbSignBaseVoteOptionType getVote() {
        return vote;
    }
    public void setVote(PbBean.PbSignBaseVoteOptionType vote) {
        this.vote = vote;
    }
    public List<String> getImageList() {
        return imageList;
    }
    public void setImageList(List<String> imageList) {
        this.imageList = imageList;
    }
    public String getURLToken(String url) {
        return mURLToken.get(url);
    }
    public void setURLToken(Map<String, String> mURLToken) { this.mURLToken = mURLToken; }
    public void setEditDescribeList(List<EditDescribe> editDescribeList) { this.editDescribeList = editDescribeList; }
    public List<EditDescribe> getEditDescribeList() { return editDescribeList; }
    public void setEditDescribeList(EditDescribe editDescribeList) {
        this.editDescribeList.add(editDescribeList);
    }
    public void deleteEditDescribeList() { editDescribeList.clear(); }
    public Context getContext() {
        return mContext;
    }
    public void setContext(Context mContext) { this.mContext = mContext; }
    public void clearContext() { this.mContext = null; }
    public boolean ismIsUpload() {
        return mIsUpload;
    }
    public void setmIsUpload(boolean mIsUpload) { this.mIsUpload = mIsUpload; }
    @Override
    public int describeContents() { return 0; }
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeString(this.mDescribe);
        dest.writeStringList(this.imageList);
        dest.writeInt(this.mURLToken.size());
        for(Map.Entry<String, String> entry : this.mURLToken.entrySet()) {
            dest.writeString(entry.getKey());
            dest.writeString(entry.getValue());
        }
        dest.writeList(this.editDescribeList);
        dest.writeInt(this.vote == null ? -1 : this.vote.ordinal());
    }
}
